<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script src="http://yui.yahooapis.com/3.4.1/build/yui/yui-min.js"></script>
</head>
<body>
<div>信箱测试</div>
<div>

<script type="text/javascript">
var formConfig = '[{"cname":"姓名","ename":"xingming","type":"text","required":true},'+
                  '{"cname":"电话","ename":"dianhua","type":"text","regex":["^[0-9]+-*[0-9]+$","电话号码的格式：xxxx-xxxx或者xxxxxx"]},'+
                  '{"cname":"地址","ename":"dizhi","type":"text"},'+
                  '{"cname":"类别","ename":"leixing","type":"select","options":["你好","他好"]},'+
                  '{"cname":"公开","ename":"gongkai","type":"checkbox"},'+
                  '{"cname":"内容","ename":"content","type":"textarea","required":true,"rows":5,"cols":80}]';
var hiddens = '{"_modelName":"com.m3958.firstgwt.server.model.XinJian",'+
		'"_operationType":"add",'+
		'"_relationModelId":11252,'+//信箱目录ID，必须提供
		'"siteId":8920}';//站点ID，必须提供
var ss = '#formConfig=' + encodeURIComponent(formConfig) + "&" + "hiddens=" + encodeURIComponent(hiddens);
document.write('<iframe scrolling="auto" src="/xinjian.html' + ss + '" frameborder="0" height="800" width="100%"></iframe>');
</script>

<script type="text/javascript">
YUI().use('node', 'event','io-form','json-parse','querystring','history','dump', function (Y) {
	var s = window.location.href + "";
	s = s.substring(s.indexOf('?')+1);
	alert(Y.dump(Y.QueryString.parse(s)));
});
function lzw_encode(s) {
    var dict = {};
    var data = (s + "").split("");
    var out = [];
    var currChar;
    var phrase = data[0];
    var code = 256;
    for (var i=1; i<data.length; i++) {
        currChar=data[i];
        if (dict[phrase + currChar] != null) {
            phrase += currChar;
        }
        else {
            out.push(phrase.length > 1 ? dict[phrase] : phrase.charCodeAt(0));
            dict[phrase + currChar] = code;
            code++;
            phrase=currChar;
        }
    }
    out.push(phrase.length > 1 ? dict[phrase] : phrase.charCodeAt(0));
    for (var i=0; i<out.length; i++) {
        out[i] = String.fromCharCode(out[i]);
    }
    return out.join("");
}

// Decompress an LZW-encoded string
function lzw_decode(s) {
    var dict = {};
    var data = (s + "").split("");
    var currChar = data[0];
    var oldPhrase = currChar;
    var out = [currChar];
    var code = 256;
    var phrase;
    for (var i=1; i<data.length; i++) {
        var currCode = data[i].charCodeAt(0);
        if (currCode < 256) {
            phrase = data[i];
        }
        else {
           phrase = dict[currCode] ? dict[currCode] : (oldPhrase + currChar);
        }
        out.push(phrase);
        currChar = phrase.charAt(0);
        dict[code] = oldPhrase + currChar;
        code++;
        oldPhrase = phrase;
    }
    return out.join("");
}

var s = '[{cname:"姓名",ename:"xingming",type:"text",required:true},'+
 '{cname:"电话",ename:"dianhua",type:"text",regex:[/^[0-9]+-*[0-9]+$/,"电话号码的格式：xxxx-xxxx或者xxxxxx"]},'+
 '{cname:"类别",ename:"leixing",type:"select",options:["你好","他好"]},'+
 '{cname:"公开",ename:"gongkai",type:"checkbox"},'+
 '{cname:"内容",ename:"content",type:"textarea",required:true,rows:"5",cols:"80"}]';
document.write("orign:" + s.length);
document.write("<br/>");
s = lzw_encode(s);
document.write("compressed:" + s.length);
document.write("<br/>");
s = encodeURIComponent(s);
document.write("encode:" + s.length);
document.write("<br/>");
s = lzw_encode(s);
document.write("compressed:" + s.length);
document.write("<br/>");
document.write(s);
</script>
</div>
</body>
</html>